<template>
	<view class="">
		<u-navbar title-size="36" height="42" :border-bottom="false" title="线索填报"></u-navbar>
		<view class="new-page">
			<view class="page-main">
				<view class="form-row flex-center">
					<view class="form-label">姓名</view>
					<view class="flex_bd">
						<input type="text" value="" class="ui-input" v-model="name" placeholder="请输入购机人姓名"
							placeholder-style="color:#BFBFBF;" />
					</view>
				</view>
				<view class="form-row flex-center">
					<view class="form-label">电话</view>
					<view class="flex_bd">
						<input type="digit" maxlength="11" class="ui-input" v-model="tel" value=""
							placeholder="请输入购机人联系方式" placeholder-style="color:#BFBFBF;" />
					</view>
				</view>
				<view class="form-row form-ht-row ">
					<view class="form-label">请选择采购机型及数量</view>
					<view class="flex_bd">
						<view class="dev-row flex-center">
							<view class="flex_bd">
								<view class="dev-select" @click="cateShow = true">
									<view class="flex_bd">
										<input disabled type="text" value="ZE60E-10" placeholder="请选择设备"
											placeholder-style="color:#BFBFBF;" />
									</view>
									<image src="../../static/images/dw.png" class="dicon" mode=""></image>
								</view>
								<view class="dev-numbox">
									<input type="number" value="2" placeholder="数量" />
									<view class="t">台</view>
								</view>
							</view>
						</view>
						<view class="dev-row flex-center" v-for="(item,index) in list" :key="index">
							<view class="flex_bd">
								<view class="dev-select" @click="cateShow = true">
									<view class="flex_bd">
										<input disabled type="text" v-model="item.name" value="" placeholder="请选择设备"
											placeholder-style="color:#BFBFBF;" />
									</view>
									<image src="../../static/images/dw.png" class="dicon" mode=""></image>
								</view>
								<view class="dev-numbox">
									<input type="number" v-model="item.number" value="" placeholder="数量" />
									<view class="t">台</view>
								</view>
							</view>
							<image src="../../static/images/de.png" class="del-icon" mode=""
								@click="list.splice(index,1)"></image>
						</view>
						<view class="dev-link" @click="add">+ 新增采购</view>
					</view>
				</view>
				<view class="form-row flex-center" @click="regionClick()">
					<view class="form-label">请选择省市区</view>
					<view class="flex_bd">
						<view class="region">{{region}}</view>
					</view>
					<image src="../../static/images/dw.png" class="dicon" mode=""></image>
				</view>
				<view class="form-row">
					<textarea value="" @input="descInput" v-model="desc" placeholder="我还有其他要求…"
						placeholder-style="color:#BFBFBF;" class="textarea" />
					<view class="num-bar">{{remnant}}/200</view>
				</view>
			</view>
			<view class="btn-foot">
				<button type="default" class="btn btn-submit" @click="submit">提交</button>
			</view>
			<u-picker v-model="show" mode="region" @confirm="confirm"></u-picker>
			<u-picker @columnchange="columnchange" mode="multiSelector" v-model="cateShow" :range="multiSelector"
				:defaultSelector="defaultSelector"></u-picker>
			<!--  -->
			<u-popup v-model="show1" mode="center" border-radius="20" width="92%">
				<view class="popup-content">
					<view class="popup-head">
						<view class="popup-title">
							<image src="../../static/images/infofill.png" mode="" class="failed-icon"></image>提交失败
						</view>
						<image src="../../static/images/close.png" class="close" mode="" @click="show1 = false"></image>
					</view>
					<view class="popup-body">
						<view class="popup-desc">
							对不起，您推荐的线索已经被人捷足先登了，请推荐其他好友信息
						</view>
					</view>
				</view>
			</u-popup>
			<u-top-tips ref="uTips" :navbar-height="statusBarHeight + navbarHeight"></u-top-tips>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				cateShow: false,
				multiSelector: [
					['起重机', '混凝土机械'],
					['泵车', '湿喷机'],
					['ZE60E-10', 'ZE60E-10', 'ZE60E-10']
				],
				defaultSelector: [0, 0, 0],
				show: false,
				show1: false,
				region: '',
				remnant: '0',
				desc: '',
				list: [],
				set: [{
					name: '',
					number: ''
				}],
				// 状态栏高度，H5中，此值为0，因为H5不可操作状态栏
				statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
				// 导航栏内容区域高度，不包括状态栏高度在内
				navbarHeight: 42,
				name: '',
				tel: ''
			}
		},
		onLoad() {

		},
		methods: {
			regionClick() {
				this.show = true
			},
			confirm(e) {
				console.log(e)
				this.region = e.province.label + '-' + e.city.label + '-' + e.area.label
			},
			descInput(e) {
				this.remnant = e.detail.value.length
			},
			columnchange(e) {
				let column = e.column,
					index = e.index;
				this.defaultSelector[column] = index;
				switch (column) {
					case 0:
						switch (index) {
							case 0:
								this.multiSelector[1] = ['泵车', '湿喷机']
								this.multiSelector[2] = ['ZE60E-10', 'ZE60E-10', 'ZE60E-10']
								break
							case 1:
								this.multiSelector[1] = ['泵车2', '湿喷机2']
								this.multiSelector[2] = ['AE60E-10', 'AE60E-10', 'AE60E-10']
								break
						}
						this.defaultSelector.splice(1, 1, 0)
						this.defaultSelector.splice(2, 1, 0)
						break
					case 1: //拖动第2列
						switch (this.defaultSelector[0]) { //判断第一列是什么
							case 0:
								switch (this.defaultSelector[1]) {
									case 0:
										this.multiSelector[2] = ['北京', '上海', '广州']
										break
									case 1:
										this.multiSelector[2] = ['东京', '北海道']
										break
								}
								break
							case 1:
								switch (this.defaultSelector[1]) {
									case 0:
										this.multiSelector[2] = ['伦敦', '曼彻斯特']
										break
									case 1:
										this.multiSelector[2] = ['巴黎', '马赛']
										break
								}
								break
						}
						this.defaultSelector.splice(2, 1, 0)
						break
				}
			},
			openUrl(e) {
				console.log(e)
				uni.navigateTo({
					url: e
				});
			},
			add() {
				var res = this.set;
				this.list.push(res[0])
			},
			submit() {
				var reg = /^1[3456789]\d{9}$/;
				if (this.name == '') {
					this.$refs.uTips.show({
						title: '姓名格式错误，请检查',
						type: 'error',
						duration: '1000'
					});
				} else if (!reg.test(this.tel)) {
					this.$refs.uTips.show({
						title: '联系方式格式错误，请检查',
						type: 'error',
						duration: '1000'
					});
				}else{
					this.show1 = true
				}
			}
		}
	}
</script>

<style lang="scss">
	.dev-row {
		margin-bottom: 16rpx;

		>.flex_bd {
			display: flex;
			align-items: center;
		}

		.dev-select {
			width: 334rpx;
			display: flex;
			align-items: center;
			padding: 0 20rpx;
			height: 80rpx;
			background: #FFFFFF;
			border: 1px solid #DDDDDD;
		}

		.dev-numbox {
			margin-left: 20rpx;
			display: flex;
			align-items: center;

			input {
				padding: 0 16rpx;
				width: 94rpx;
				height: 80rpx;
				background: #FFFFFF;
				border: 1px solid #DDDDDD;
			}

			.t {
				margin-left: 10rpx;
			}
		}

		.del-icon {
			width: 30rpx;
			height: 30rpx;
		}

		input {
			font-size: 28rpx;
		}
	}

	.dev-link {
		font-size: 28rpx;
		color: #FE6714;
	}

	.form-ht-row {
		.form-label {
			margin-bottom: 30rpx;
		}
	}

	.num-bar {
		text-align: right;
		color: #BFBFBF;
	}

	.form-row {
		.dicon {
			width: 28rpx;
			height: 28rpx;
		}
	}

	.new-page {
		position: relative;
		padding: 16rpx 32rpx 0;
		min-height: calc(100vh - 62px);

		.bg {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
		}
	}

	.page-main {
		position: relative;
		z-index: 99;
		background-color: #FFFFFF;
		// padding: 30rpx;
		padding-bottom: 0;
		border-radius: 20rpx;
	}

	.form-row {
		background: #F3F4F6;
		border-radius: 12rpx;
		padding: 30rpx;
		margin-bottom: 30rpx;

		.form-label {
			margin-right: 32rpx;
			color: #303337;
		}

		.textarea {
			height: 130rpx;
			font-size: 28rpx;
		}

		.ui-input {
			font-size: 28rpx;
		}
	}

	.btn-foot {
		padding: 24rpx;
		position: absolute;
		left: 0;
		bottom: 0;
		width: 100%;
	}

	.popup-content {
		.popup-head {
			position: relative;
			padding: 48rpx 24rpx 40rpx;

			.popup-title {
				font-size: 40rpx;
				color: #303337;
				font-weight: 600;
				display: flex;
				justify-content: center;
				line-height: 64rpx;

				.failed-icon {
					width: 76rpx;
					height: 80rpx;
				}
			}

			.close {
				width: 48rpx;
				height: 48rpx;
				position: absolute;
				right: 24rpx;
				top: 24rpx;
			}

		}

		.popup-body {
			padding: 0 70rpx 140rpx;

			.popup-desc {
				font-size: 32rpx;
				color: #666666;
				line-height: 52rpx;
				padding-left: 8rpx;
				text-align: center;
			}
		}
	}
	
	 .u-error{
		background-color: #FFE6E7!important;
		color: #FD523B!important;
		text-align: left!important;
		padding:24rpx 32rpx!important;
		justify-content: flex-start!important;
	}
</style>
